#
# \file
# \brief
# \author Marco Antonio Pinto Orellana
#
# -------------------------------------------------------------------------
#
# Copyright (C) 2012  (see AUTHORS file for a list of contributors)
# http://opentonitruum.sourceforge.net
#
# This file is part of OpenTonitruum - a simulator/library of signal trans-
# mission, modulation and processing in a wireless environment.
#
# OpenTonitruum is free software: you can redistribute it and/or modify it 
# under the terms of the Lesser GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at 
# your option) any later version.
#
# OpenTonitruum is distributed in the hope that it will be useful, but WITH-
# OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with OpenTonitruum.  If not, see <http://www.gnu.org/licenses/>.
#
# -------------------------------------------------------------------------
#

from PhysicalLayer import *
from LinkLayer import *

class Equipment(object):
	def __init__(self, id, protocol, environment):
		self.transmissionSystem = environment.transmissionSystem
		self.physicalLayer = environment.physicalLayer
		self.linkLayer = LinkLayer(id, protocol, self.physicalLayer)
		
	def send(self, destin, data):
		self.linkLayer.send(destin, data)

class Environment(object):
	def __init__(self):
		self.transmissionSystem = TransmissionSystem()
		self.physicalLayer = PhysicalLayer(self.transmissionSystem, transmittingTimeByBit = 0.1)
		activate(self.physicalLayer, self.physicalLayer.run())

class TestEnvironment(Process):
	def __init__(self):
		Process.__init__(self)
		initialize()
		activate(self, self.run())
	
	def run(self):
		env = Environment()
		master = Equipment(0, "HDLC", env)
		slave_len = 3
		slaves = [Equipment(i+1, "HDLC", env) for i in range(slave_len)]
		master.send(1, [[1], [1, 0, 1, 1, 0, 1, 0]])
		master.send(2, [[1, 1,1,1,1,0,1,0,1,0,0, 1, 0, 1, 0]])
		master.send(1, [[1, 0, 1, 0, 1, 0]])
		yield hold, self, 1

TestEnvironment()
simulate(until = 10000)

